package com.rou.im.framework.core.processorstack.processor;

import com.rou.im.framework.core.Request;
import com.rou.im.framework.core.RequestVO;
import com.rou.im.framework.core.context.RequestContextHolder;
import com.rou.im.framework.core.processorstack.Processor;
import com.rou.im.framework.core.processorstack.StackInvocation;
import com.rou.im.framework.core.serializer.SerializerManager;

/**
 * <p>
 *     入栈数据装换处理器
 *     byte[]---> request bean
 * </p>
 *
 * @author GaoShuangWen
 * @since 2020-05-20 21:21
 */
public class InboundDataChangeProcessor implements Processor {

    private final SerializerManager serializerManager;

    public InboundDataChangeProcessor() {
        serializerManager = new SerializerManager();
    }

    @Override
    public void process(Request request, StackInvocation invocation) {
        // 将请求体装换成对象
        RequestVO requestVO = serializerManager.deserialize(request);
        // 将请求vo插入到上下文中
        RequestContextHolder.getContext().setRequestVO(requestVO);

        invocation.invoke(request);


    }

}
